#ifndef ACAPELLA_SYNCHRONIZE_SPINLOCK_WINDOWS_HPP
#define ACAPELLA_SYNCHRONIZE_SPINLOCK_WINDOWS_HPP

#include <windows.h>

namespace acapella
{
namespace synchronize
{


class spin_lock
{
public:
	spin_lock()
	{
		::InitializeCriticalSection(&v_);
	}

	~spin_lock()
	{
		::DeleteCriticalSection(&v_);
	}

	bool try_lock()
	{
		return ::TryEnterCriticalSection(&v_) == TRUE;
	}

	void lock()
	{
		::EnterCriticalSection(&v_);
	}

	void unlock()
	{
		::LeaveCriticalSection(&v_);
	}

private:
	CRITICAL_SECTION  v_;

	spin_lock(const spin_lock&);
	spin_lock& operator=(const spin_lock&);
};


}
}


#endif
